home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / sound / players / eplay20.arc / eplay.c next >
C/C++ Source or Header  |  1990-07-22  |  25KB  |  889 lines

  1. /*
  2.  
  3.                      *********** Eplay ***********
  4.                           Version 2.0 07/22/90
  5.                              Public Domain
  6.  
  7.                       The STe audio sample player
  8.                       (via the STe DMA soundchip)
  9.  
  10.                              By: AAron nAAs
  11.                        AAron@sun.soe.clarkson.edu
  12.  
  13.                      *****************************
  14.  
  15.  
  16. As stated previously, I am releasing this into the public domain, though I
  17. reserve all rights to the executable and the sourcecode.  Copying and
  18. distributing this package AS A WHOLE is not only permitted, but encouraged.
  19. If profit can be made using this package, or ANY part of it, an agreement
  20. must be made with me before any profit can be collected.  
  21.  
  22. Address:                       E-Mail:
  23.          AAron nAAs                    AAron@sun.soe.clarkson.edu
  24.          8 W. Elizabeth St.
  25.          Skaneateles, NY (USA)
  26.          13152
  27.  
  28.  
  29. */
  30. #include <stdio.h>
  31. #include <osbind.h>
  32. #include <ctype.h>
  33. #include <stat.h>
  34. #include <basepage.h>
  35.  
  36. #define MAX 32000           /* Maximum size of block to file read */
  37. #define YES 1
  38. #define NO 0
  39. #define DEFAULT_C 0x0081    /* Default control byte: Mono, 12kHz */
  40. #define DEFAULT_E 0x0001    /* Default enable  byte: Play once   */
  41.  
  42. #define MASK_MICROWIRE 0xff8924L
  43. #define DATA_MICROWIRE 0xff8922L
  44.  
  45. extern char *lmalloc();     /* needed to do dynamic memory stuff */
  46.  
  47. main(argc, argv)
  48. int argc;
  49. char *argv[];
  50. {
  51. char infile[80],            /* Name of sample file */
  52.      conv_str[20],          /* To say what conversion is being done */
  53.      conv_type = ' ',       /* For program to realize what conversion to do */
  54.      mix_str[40],           /* To say what mix is being done */
  55.      *start,                /* Sample start address */
  56.      *end,                  /* Sample end address */
  57.      *buffer;               /* Where to load sample to */
  58.  
  59. FILE *fp;                   /* Standard C file handle */
  60.  
  61. long fsize,                 /* File size */
  62.      needed;                /* Amount needed to malloc */
  63.  
  64. int level,                  /* Used to get levels/volumes from command line */
  65.     master_level,           /* Volume-Master from command line to display */
  66.     left_level,             /* Volume-Left from command line to display */
  67.     right_level,            /* Volume-right from command line to display */
  68.     treble_level,           /* Treble level from command line to display */
  69.     bass_level;             /* Bass level from command line to display */
  70.  
  71. unsigned gavememory = NO,   /* If memory locations are given in command line */
  72.          gavefile = NO,     /* If a filename is given in command line */
  73.          left = YES,        /* If wanted to play through left speaker */
  74.          right = YES,       /* If wanted to play through right speaker */
  75.          putaddress = NO,   /* If we have to give sound chip an address */
  76.          putenable = NO,    /* If we have to give sound chip an enable byte */
  77.          errored = NO,      /* If an error occured during sample loading */
  78.          putcontrol = NO,   /* If we have to give sound chip a control byte */
  79.          gavekill = YES,    /* If user DOESN'T want to protect the sample */
  80.          gaveinfo = YES,    /* If user wants info */
  81.          reserved_mem = NO, /* If we malloced any memory */
  82.          master_volume = 0, /* Word to set master volume */
  83.          left_volume = 0,   /* Word to set left volume */
  84.          right_volume = 0,  /* Word to set right volume */
  85.          treble = 0,        /* Word to set treble */
  86.          bass = 0,          /* Word to set bass */
  87.          mix = 0,           /* Word to set mix */
  88.          playing_rate,      /* To display playing sample rate */
  89.          counter,           /* For various loops */
  90.          cur,               /* Used in uppercase conversion of command line */
  91.          amount,            /* Number of bytes we end up loading from file */
  92.          control_b,         /* Word to set Sound mode control of sound chip */
  93.          enable_b,          /* Word to set sound chip playing */
  94.          *s_enable,         /* Loc of enable register */
  95.          *s_base,           /* Loc of frame base address register */
  96.          *s_end,            /* Loc of frame end address register */
  97.          *s_control;        /* Loc of Sound mode control register */
  98.  
  99.  
  100. /* If passed no arguements */
  101.  
  102. if (argc < 2)
  103.   {
  104.   printf("Try: eplay -HELP\n");
  105.   return;
  106.   }
  107.  
  108.  
  109. /* Setup register locations */
  110.  
  111. s_enable  = (unsigned *) 0xff8900L;
  112. s_base    = (unsigned *) 0xff8902L;
  113. s_end     = (unsigned *) 0xff890eL;
  114. s_control = (unsigned *) 0xff8920L;
  115.  
  116.  
  117. /* Zero addresses */
  118.  
  119. start     = (char *)0L;
  120. end       = (char *)0L;
  121.  
  122. /* Find out what addresses are in the DMA soundchip, for default */
  123.  
  124. for (counter = 0; counter < 3; counter ++)
  125.    {
  126.    (long)start <<= 8;
  127.    (long)end   <<= 8;
  128.    (long)start |= (peekw(s_base+counter) & 0x00ff);
  129.    (long)end   |= (peekw(s_end+counter)  & 0x00ff);
  130.    }
  131.  
  132. infile[0]='\0';
  133.  
  134.  
  135. /* Get what is in the DMA soundchip, for default */
  136.  
  137. control_b = peekw(s_control);
  138. enable_b  = peekw(s_enable);
  139.  
  140.  
  141. /* Make command line uppercase */
  142.  
  143. for (counter = 1; counter < argc; counter ++)
  144.    for (cur = 0; cur < strlen(argv[counter]); cur ++)
  145.       if (isalpha(argv[counter][cur]))
  146.          if (islower(argv[counter][cur]))
  147.             argv[counter][cur] = toupper(argv[counter][cur]);
  148.  
  149.             
  150. /* Figure out what the user wants */
  151.  
  152. for (counter = 1; counter < argc;)
  153.   {
  154.   if (argv[counter][0] == '-')
  155.      {
  156.      if (strcmp(&argv[counter][1], "HELP") == 0)
  157.         {
  158.         printf("Usage:\n");
  159.         printf("   [[-L[{R,L}][U]] <filename>] Load:   Load Sample [Right/Left] [Unsigned].\n");
  160.         printf("   [-S <0xhhhhhh> <0xhhhhhh>]  Sample: Sample location.\n");
  161.         printf("   [-M{S,M}]                   Mode:   Stereo/Mono.\n");
  162.         printf("   [-R{0,1,2,3}]               Rate:   6.25/12.5/25/50kHz.\n");
  163.         printf("   [-P{O,L,S}]                 Play:   Once/Loop/Stop.\n");
  164.         printf("   [-V{M,L,R} dd]              Volume: Set Master/Left/Right to dd dB.\n");
  165.         printf("   [-T dd]                     Treble: Set Treble to dd dB.\n");
  166.         printf("   [-B dd]                     Bass:   Set Bass to dd dB.\n");
  167.         printf("   [-X{0,1,2,3}]               Mix:    Set mix -12dB/GI/no GI/Reserved.\n");
  168.         printf("   [-K]                        Keep:   Protect sample memory.\n");
  169.         printf("   [-I]                        Info:   Suppress info listing.\n");
  170.         printf("   [-HELP]                     Help:   This list.\n");
  171.         printf("   [-REMOTEHELP]\n\n");
  172.         printf("Key: Elements between [ and ] are optional,\n");
  173.         printf("     An element between { and } must be selected.\n");
  174.         printf("     Memory locations must be in hex and begin with '0x'\n");
  175.         printf("If only <filename> is given, then it defaults to '-MM -R1 -PO'.\n");
  176.         printf("If -L[{R,L}] or -S is used, NOTHING changes by default,\n");
  177.         printf(" which means it must specifically be told to play, and how.\n");
  178.         gaveinfo = NO;
  179.         counter ++;
  180.         }
  181.      else
  182.      if (strcmp(&argv[counter][1], "REMOTEHELP") == 0)
  183.         {
  184.         printf("Eplay version 2.0 07/22/90 (Public Domain, see Docs)\n\n");
  185.         printf("Something really confusing ya huh?\n");
  186.         printf("For REAL help, contact:\n");
  187.         printf("  AAron@sun.soe.clarkson.edu\n");
  188.         gaveinfo = NO;
  189.         counter ++;
  190.         }
  191.      else
  192.      if (argv[counter][1] == 'M')  /******* Get Mode */
  193.         {
  194.         if (argv[counter][2] == 'S')
  195.            control_b &= 0xff7f;    /* clear mode bit (stereo mode)     */
  196.         else
  197.         if (argv[counter][2] == 'M')
  198.            control_b |= 0x0080;    /* set   mode bit (monophonic mode) */
  199.         else
  200.            {
  201.            printf("Mode '%c' not supported.\n", argv[counter][2]);
  202.            return;
  203.            }
  204.         putcontrol = YES;
  205.         counter ++;
  206.         }
  207.      else
  208.      if (argv[counter][1] == 'V')  /******* Get Volume */
  209.         {
  210.         if ( ((counter + 1) < argc) && isnumber(counter + 1, argv))
  211.            {
  212.            level = 0;
  213.            sscanf(argv[counter + 1], "%d", &level);
  214.            if (level &